package br.poli.ecomp.tcc.stimultimidia.view.components
{
	import br.poli.ecomp.tcc.stimultimidia.event.TelaCadastroEvent;
	import br.poli.ecomp.tcc.stimultimidia.model.vo.UsuarioVO;
	
	import flash.events.MouseEvent;

	public class TelaCadastro extends TelaCadastroSWC
	{
		public function TelaCadastro()
		{
			super();
			this.btFechar.addEventListener(MouseEvent.CLICK,onFechar);
			this.btCadastrar.addEventListener(MouseEvent.CLICK, onCadastrar);
		}
		
		private function onFechar(e:MouseEvent):void
		{
			var evt:TelaCadastroEvent= new TelaCadastroEvent( TelaCadastroEvent.FECHAR  );
			this.dispatchEvent( evt );
		}
		
		
		private function onCadastrar(e:MouseEvent):void
		{
			if( validaCampos () ){
				var user:UsuarioVO = new UsuarioVO();
				user.nome = this.campoNome.text;
				user.dataNasc = this.campoDia.text +"/"+this.campoMes.text+"/"+this.campoAno;
				
				//user.sexo = this.campoSexo
				user.login = this.campoLogin.text; 
				user.senha = this.campoSenha.text;
				
				var evt:TelaCadastroEvent= new TelaCadastroEvent( TelaCadastroEvent.SINGUP, user  );
				this.dispatchEvent( evt );
				
			}
			
		}
		
		private function validaCampos():Boolean
		{
			var boo:Boolean = false;
			if(this.campoSenha.text == this.campoSenha2.text ){
				if(this.campoNome.text != ""){
					boo = true;
				}else{
					boo = false;
				}
			}else{
				boo = false;
			}
				
				
			return boo;
		}
		
		
	}
}